#include "version.h"

#include <QDebug>

namespace qrcode{

Version::Version()
{
}

Version::Version(int version, char errorlevel, int numDataBits, int numDataCodewords,
                 int numeric, int alphaNumeric, int byte, int hanzi, int ECCodewordsPerBlock,
                 int blockInGroup1, int numDataCodewordsInGroup1,
                 int blockInGroup2, int numDataCodewordsInGroup2)
    :version(version), errorCorrectionLevel(errorlevel), numDataBits(numDataBits),
      numDataCodewords(numDataCodewords), numeric(numeric), alphanumeric(alphaNumeric),
      byte(byte), hanzi(hanzi), ECCodewordsPerBlock(ECCodewordsPerBlock),
      blockInGroup1(blockInGroup1), numDataCodewordsInGroup1(numDataCodewordsInGroup1),
      blockInGroup2(blockInGroup2), numDataCodewordsInGroup2(numDataCodewordsInGroup2)
{
    eci = byte-2;
    if(numDataCodewords != (blockInGroup1*numDataCodewordsInGroup1 +
                            blockInGroup2*numDataCodewordsInGroup2)) {
        qDebug() << "version.cpp: " << version <<" " << errorlevel <<"Codewords分组数据错误";
    }
    if(numDataBits != numDataCodewords*8){
        qDebug() << "version.cpp: 数据码字数错误";
    }
}

int Version::GetVersion()
{
    return version;
}

char Version::GetErrorCorrectionLevel()
{
    return errorCorrectionLevel;
}

int Version::GetNumDataBits()
{
    return numDataBits;
}

int Version::GetNumDataCodewords()
{
    return numDataCodewords;
}

int Version::GetNumeric()
{
    return numeric;
}

int Version::GetAlphaNumeric()
{
    return alphanumeric;
}

int Version::GetByte()
{
    return byte;
}

int Version::getEci() const
{
    return eci;
}

int Version::GetHanzi()
{
    return hanzi;
}

std::vector<int> Version::GetBreakInfo()
{
    std::vector<int> vec{ECCodewordsPerBlock, blockInGroup1, numDataCodewordsInGroup1,
                        blockInGroup2, numDataCodewordsInGroup2};
    return vec;
}

}
